import HTMLParser
import urllib
import re
import string


urlString = "http://www.nyiix.net/members_ip.php"
urlText = []
pathOut = "ixp_members.txt"


class Parse11 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "span":
            for name,value in attrs:
                if name == "style" and value == "font-size: 8pt":
                    self.check = True
    
    def handle_data (self, data):
        if self.check == True and re.match("^(ASN?)?\d+ *$",data):
            data = string.lstrip(data, "AS")
            data = string.lstrip(data, "N")
            data = string.rstrip(data)
            if data not in urlText:
                urlText.append(data)
        self.check = False


lparser = Parse11()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "11 %s" % item
fileOut.close()